package com.hr.controller;

import com.hr.pojo.Schedule;
import com.hr.service.ScheduleService;
import com.hr.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author DSL
 * @create 2024-10-30 12:02
 */
@CrossOrigin//允许跨域
@RestController// @Controller + @ResponseBody: 返回json数据
@RequestMapping("schedule")//用于设置请求路径的前缀
@Slf4j//日志相关的注解
public class ScheduleController {
    @Autowired
    private ScheduleService scheduleService;
//    pageSize：每页显示的条数
//    currentPage：当前页码
    @GetMapping  ("/{pageSize}/{currentPage}")
    public R selectPageList(@PathVariable int pageSize,@PathVariable int currentPage){
        R page =scheduleService.page(pageSize,currentPage);
        System.out.println("成功");
        log.info("查询全部数据:{}",page);
        return page;
    }
    @DeleteMapping("/{id}")
    public R remove(@PathVariable Integer id){
        R remove =scheduleService.deleteById(id);
        log.info("查询全部数据:{}",remove);
        return remove;
    }
//    增加
//@RequestBody：将请求体中的json数据封装到实体类中
    @PostMapping
    public R save(@RequestBody Schedule schedule){
        R insert=scheduleService.insert(schedule);
        System.out.println("增加成功");
        log.info("添加数据:{}",insert);
        return insert;
    }
//修改
    @PutMapping
    public R update(@RequestBody Schedule schedule){
    R updated=scheduleService.update(schedule);
        System.out.println("修改成功");
        log.info("修改数据:{}",updated);
        System.out.println("你好!");
        System.out.println("dds");
        System.out.println("sss");
    return updated;
    }
}
